package com.food.dao.service;

import java.io.InputStream;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.food.dao.MemberDAOJdbc;
import com.food.dao.in.MemberDAO;
import com.food.model.Member;

public class MemberService {
	//getBytes()
	
	private MemberDAO dao = new MemberDAOJdbc();
	
	public void insertMember(Member bean,InputStream is, int size){
		if(bean!=null) {
			dao.insertMember(bean,is,size);
		}
	}
	public void updateMember(Member bean,InputStream is, int size){
		if(bean!=null) {
			dao.updateMember(bean.getMbname(), bean.getMbsex(), bean.getMbidentity(),
					bean.getMbbirth(), bean.getMbnick(),bean.getMbemail(), bean.getMbtel(),
					bean.getMbaddr(), bean.getMbaccount(), bean.getMbimg(),
					bean.getMbid(),is,size);
		}
	}
	public List<Member> select(Member bean) {
		List<Member> result = null;
		if(bean!=null && bean.getMbaccount().trim()!="") {
			Member temp = dao.findMemberByAccount(bean.getMbaccount());
			if(temp!=null) {
				result = new ArrayList<Member>();
				result.add(temp);
			}
		} else {
			return result;
		}
		return result;
	}
	public Member login(String username, String password) {
		Member bean = dao.findMemberByAccount(username);
		if(bean!=null) {
			if(password!=null && password.length()!=0) {
				byte[] pass = bean.getMbpassword();	//��Ʈw�x�s���ýX
				byte[] temp = password.getBytes();	//�ϥΪ̿�J����X
			//	temp = md.digest(temp);				//�ýX
				if(Arrays.equals(pass, temp)) {
					return bean;
				}
			}
		}
		return null;
	}
	public Member findMember(Member bean){
		return dao.findMember(bean.getMbid());
	}
}
